#include "WiFi.h"
#include "esp_wifi.h"
#include "nvs_flash.h"
#include "hardware/MyWifi.h"
#include "hardware/mqtt.h"
#include "hardware/button.h"
#include "hardware/led.h"
#include "config.h"
#include "hardware/ntp.h"

TaskHandle_t gWifiPerTaskHandle = 0;
TaskHandle_t gMqttTaskHandle = 0;
TaskHandle_t gWifiSmartTaskHandle = 0;
TaskHandle_t gBtnTaskHandle = 0;
TaskHandle_t gLedTaskHandle = 0;
TaskHandle_t gNtpTaskHandle = 0;
void hardware_init(void *pvParameters) 
{
  Serial.begin(115200);
  led_init();
  xTaskCreate(led_task, "led_task", 1024 * 2, NULL, TASK_LED_PRI, &gLedTaskHandle);
  delay(5000);
  wifi_setup();
  mqtt_setup();
  btn_init();
  ntp_init();
  xTaskCreate(wifi_perTask, "wifi_perTask", 1024 * 10, NULL, TASK_WIFI_PER_PRI, &gWifiPerTaskHandle);
  xTaskCreate(mqtt_loopTask, "mqtt_loopTask", 1024 * 10, NULL, TASK_MQTT_PRI, &gMqttTaskHandle);
  xTaskCreate(wifi_smartTask, "wifi_smartTask", 1024 * 10, NULL, TASK_WIFI_PER_PRI, &gWifiSmartTaskHandle);
  xTaskCreate(btn_task, "btn_task", 1024 * 2, NULL, TASK_BTN_PRI, &gBtnTaskHandle);
  xTaskCreate(ntp_task, "ntp_task", 1024 * 2, NULL, TASK_NTP_PRI, &gBtnTaskHandle);
  vTaskDelete(NULL);
}
void setup() {
  xTaskCreate(hardware_init, "hardware_init", 1024 * 30, NULL, TASK_LED_PRI, NULL);
}

void loop() {
  // put your main code here, to run repeatedly:

}